﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext;
using Coolite.Ext.Web;

public partial class HR_UserList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Cookies.getCookies("cDeptID")!="3")
        {
            Window1.Show();
        }

        Query q = new Query(CxUserBase.Schema);
        q.AddWhere("DepID", 3);
        q.AddWhere("LevelID", 1);
        Store2.DataSource = q.ExecuteDataSet();
        Store2.DataBind();
    }
     protected void RowSelect(object sender, AjaxEventArgs e)
     {
         string uID = e.ExtraParams["uID"];
         //TfUserId.Text = uID;
         Query q = new Query(VwUserBase.Schema);
         q.SetSelectList("username,depid,deptname");
         q.AddWhere("uID", uID);
         IDataReader dr = q.ExecuteReader();
         if(dr.Read())
         {
             TfDeptID.Value = dr[1].ToString();
             tfhiddenid.Value = uID;
             TfDeptName.Text = dr[2].ToString();
             tflbusername.Text = dr[0].ToString();
             //FormPanel1.Title = "员工诚信档案记录表:" + dr[0].ToString();
         }
         
     }
     [AjaxMethod]
     protected void SubReportAdd(object sender, AjaxEventArgs e)
     {
         if (tfhiddenid.Value.ToString() == "")
         {
             Err.Warning("请在左侧列表选择一个员工！", MessageBox.Icon.WARNING);
         }
         else
         {
             if (!(Cookies.getCookies("cDeptID") == "3"))
             {
                 Err.Warning("对不起，您没有权限进行此项操作！", MessageBox.Icon.WARNING);
             }
             else
             {
                 if (TfaDept_MasterID.SelectedIndex == -1)
                 {
                     Err.Warning("请选择部门领导！", MessageBox.Icon.WARNING);
                 }
                 else
                 {
                     //添加表单
                     Guid g = Guid.NewGuid();
                     CxStaffHr cx = new CxStaffHr();
                     cx.UserID = int.Parse(tfhiddenid.Value.ToString());
                     cx.DeptID = int.Parse(TfDeptID.Value.ToString());
                     if (TfTalkTime.Value.ToString() != "0001/1/1 0:00:00")
                     {
                         cx.TalkTime = DateTime.Parse(TfTalkTime.Value.ToString());
                     }
                     cx.TalkContent = TfTalkContent.Text == "" ? "无" : TfTalkContent.Text;
                     if (TfPunish_party_time.Value.ToString() != "0001/1/1 0:00:00")
                     {
                         cx.PunishPartyTime = DateTime.Parse(TfPunish_party_time.Value.ToString());
                     }
                     if (TfPunish_party_type.SelectedIndex != -1)
                     {
                         cx.PunishPartyType = TfPunish_party_type.SelectedItem.Text;
                     }
                     cx.PunishPartyReason = TfPunish_party_reason.Text == "" ? "无" : TfPunish_party_reason.Text;
                     if (TfPunish_penal_time.Value.ToString() != "0001/1/1 0:00:00")
                     {
                         cx.PunishPenalTime = DateTime.Parse(TfPunish_penal_time.Value.ToString());
                     }
                     if (TfPunish_penal_type.SelectedIndex != -1)
                     {
                         cx.PunishPenalType = TfPunish_penal_type.SelectedItem.Text;
                     }
                     cx.PunishPenalReason = TfPunish_penal_reason.Text == "" ? "无" : TfPunish_penal_reason.Text;
                     cx.PartyProblem = TfParty_Problem.Text == "" ? "无" : TfParty_Problem.Text;
                     cx.OtherProblem = TfOther_Problem.Text == "" ? "无" : TfOther_Problem.Text;
                     cx.EnteringUserID = int.Parse(Cookies.getCookies("cUID"));
                     cx.ADeptMasterID = int.Parse(TfaDept_MasterID.SelectedItem.Value);
                     cx.InTime = DateTime.Now;
                     cx.ADeptMasterStatus = 0;
                     cx.BossStatus = 0;
                     cx.DeptMasterStatus = 0;
                     cx.Status = 0;
                     cx.Guid = g;
                     cx.Save();
                     CXFileUpload.Sv(tffileupload, g);

                     //清空表单
                     FormPanel1.Title = "员工诚信档案记录表";
                     TfDeptName.Text = "";
                     //TfUserId.Text = "";
                     tflbusername.Text = "";
                     tfhiddenid.Clear();
                     TfDeptID.Value = "";
                     TfTalkTime.Value = "";
                     TfTalkContent.Text = "";
                     TfPunish_party_reason.Text = "";
                     TfPunish_party_time.Value = "";
                     TfPunish_party_type.Reset();
                     TfPunish_penal_reason.Text = "";
                     TfPunish_penal_time.Value = "";
                     TfPunish_penal_type.Reset();
                     TfParty_Problem.Text = "";
                     TfOther_Problem.Text = "";
                     TfaDept_MasterID.Reset();
                     Err.Warning("已提交，请等待人事领导审批！",MessageBox.Icon.NONE);

                 }
             }
         }
     }
}
